﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library;
using NCS.Library.Components;
using NCS.Library.Components.Portal;
using NCS.Library.Components.Security;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.CMSPermisions;
using NCS.Module.CMS.Library.Contents;
using NCS.Module.CMS.Library.Definitions;
using NCS.Module.CMS.Library.Distributions;
using NCS.Module.CMS.Library.Zones;
using NCS.Library.Components.Partner;
using NCS.Module.CMS.Library.Events;
using NCS.Module.CMS.Library.Feed;

namespace NCS.Module.CMS.Admin.Author
{
	public partial class EditContent : AuthenticatedControl
	{
		private ContentInfo contentInfo;
        private bool isManager, isPublisher, isCreater;
        private string curDateString = DateTime.Now.Year.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString();
	    private int contentId = 0;
	    private int inportalid = 0;
	    private int inzoneid = 0;
        private int versionid = 0;
        private string userUploadPath = Constants.UploadPath;
        private void CheckPath()
        {
            //userUploadPath += CurrentUser.UserID;// +"/Nam_" + DateTime.Now.Year.ToString();
            string folder = userUploadPath;// +"/Thang_" + DateTime.Now.Month.ToString() + "/Ngay_" + DateTime.Now.Day.ToString();
            string avatarPath = folder + "/Avatar/";

            if (!Directory.Exists(Server.MapPath(folder)))
            {
                Directory.CreateDirectory(Server.MapPath(folder));
            }
            if (!Directory.Exists(Server.MapPath(avatarPath)))
            {
                Directory.CreateDirectory(Server.MapPath(avatarPath));
            }
        }

		protected void Page_Load(object sender, EventArgs e)
		{
       
            isManager = CMSPermisionController.CheckUserPermision(CurrentUser.UserID, (int)CMSPermision.Manager, ConvertUtility.ToInt32(AppEnv.PortalId()));
            isPublisher = CMSPermisionController.CheckUserPermision(CurrentUser.UserID, (int)CMSPermision.Publisher, ConvertUtility.ToInt32(AppEnv.PortalId()));
            isCreater = CMSPermisionController.CheckUserPermision(CurrentUser.UserID, (int)CMSPermision.Creater, ConvertUtility.ToInt32(AppEnv.PortalId()));

            contentId = ConvertUtility.ToInt32(Request.QueryString["contentid"]);
            inportalid = ConvertUtility.ToInt32(Request.QueryString["inportalid"]);
            inzoneid = ConvertUtility.ToInt32(Request.QueryString["inzoneid"]);
            versionid = ConvertUtility.ToInt32(Request.QueryString["versionid"]);

            //khóa nội dung cần edit lại
            ContentController.LockContent(contentId, CurrentUser.UserID);

            contentInfo = ContentController.GetInfo(contentId);
			if (!IsPostBack)
			{
                txtContent.Language = "vi";
                CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser();
                _FileBrowser.BasePath = "/ckfinder/";
                _FileBrowser.SetupCKEditor(txtContent);

                CheckPath();
                if (contentInfo == null)
                {
                    Response.Redirect(AppEnv.ADMIN_CMD);
                }

                //txtAvatar2width.Text = Constants.ThumbWidth.ToString();
                //txtAvatar2Height.Text = Constants.ThumbHeight.ToString();
                txtSpecialAvatarHeight.Text = Constants.ThumbSpecialHeight.ToString();
                txtSpecialAvatarwidth.Text = Constants.ThumbSpecialWidth.ToString();
                //FCKeditor1.Height = 200;
                txtContent.Height = 500;               

                dropPartner.DataSource = PartnerController.GetPartners();
                dropPartner.DataBind();
                dropPartner.Items.Insert(0, new ListItem("   ---- Chọn đối tác ----", "0"));

			    LoadZones();                
			    
				MiscUtility.FillIndex(dropExpireDay, 1, 31, 1);
				MiscUtility.FillIndex(dropExpireMonth, 1, 12, 1);
				MiscUtility.FillIndex(dropExpireYear, 2000, 2020, 2020);
			}
		}
        private void LoadZones()
        {
            lstZones.Enabled = false;
            rdoContentRanks.Enabled = false;

            dropZones.Items.Clear();
            ZoneController.LoadZones(dropZones.Items, AppEnv.PortalId(), 0);
            dropZones.Items.Insert(0, new ListItem("Root", "0"));
            dropZones.SelectedValue = inzoneid.ToString();

            if (!isManager)
            {
                string permisionZoneCollection = CMSPermisionController.GetPermisionZones(CurrentUser.UserID, ConvertUtility.ToInt32(AppEnv.PortalId()));
                if (permisionZoneCollection != null && permisionZoneCollection.Length > 1)
                {
                    int i = 0;
                    while (i < dropZones.Items.Count)
                    {
                        if (permisionZoneCollection.IndexOf("|" + dropZones.Items[i].Value + "|") < 0)
                        {
                            dropZones.Items.RemoveAt(i);
                        }
                        else
                        {
                            i += 1;
                        }
                    }
                }
                else
                {
                    dropZones.Items.Clear();
                }
            }
            if (isManager || isPublisher)
            {
                lstZones.Enabled = true;
                rdoContentRanks.Enabled = true;
            }

            lstZones.Items.Clear();
            foreach (ListItem item in dropZones.Items)
            {
                lstZones.Items.Add(new ListItem(item.Text, item.Value));
            }

        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);            

            MiscUtility.SelectItemFromList(dropZones, contentInfo.Content_ZoneID.ToString());            
            
            dropEvent.DataSource = EventController.GetAll();
            dropEvent.DataBind();
            dropEvent.Items.Insert(0, new ListItem("   ---- Chọn chuyên đề ----", "0"));

            //txtTeaser.UploadDir = userUploadPath;
            //txtContent.UploadDir = userUploadPath;
            txtAvatar.fpUploadDir = userUploadPath;
            txtSpecialAvatar.fpUploadDir = userUploadPath;

            if (contentInfo.Content_Avatar != "")
                txtAvatar.fpUploadDir = contentInfo.Content_Avatar.Substring(0, contentInfo.Content_Avatar.LastIndexOf("/"));
            if(contentInfo.SpecialAvatar!="")
                txtSpecialAvatar.fpUploadDir = contentInfo.SpecialAvatar.Substring(0, contentInfo.SpecialAvatar.LastIndexOf("/"));
            
            txtHeadline.Text = contentInfo.Content_Headline;
            //FCKeditor1.Value = contentInfo.Content_Teaser;
            this.txt_teaser.Text = contentInfo.Content_Teaser;
            txtContent.Text = contentInfo.Content_Body;
            txtAvatar.Text = contentInfo.Content_Avatar;
            //txtAvatar2width.Text = contentInfo.Content_AvatarWidth.ToString();
            //txtAvatar2Height.Text = contentInfo.Content_AvatarWidth.ToString();
            txtAvatarDes.Text = contentInfo.Content_AvatarDescription;
            lbAlias.Text = contentInfo.Content_Alias;
            txtSpecialAvatar.Text = contentInfo.SpecialAvatar;
            chkAlbum.Checked = contentInfo.SetAlbum;
            txtSubTitle.Text = contentInfo.Content_SubTitle;
            txtNoteBox.Text = contentInfo.Content_NoteBox;

            txtSource.Text = contentInfo.Content_Source;
            try
            {
                dropPartner.SelectedValue = contentInfo.Content_AvatarSource.ToString();
            }
            catch 
            {
                dropPartner.SelectedIndex = -1;
            }
            dropEvent.SelectedValue = contentInfo.Event_ID.ToString();
            // ----------------------------
            DistributionInfo distinfo = DistributionController.GetDistribution(DistributionController.GetDistID(contentInfo.Content_ID));
            try
            {
                if (!IsPostBack)
                {
                    if (NCS.Library.AppEnv.GetLanguage() == "vi-VN")
                    {
                        txtDatetime.Text = distinfo.Distribution_WaittingDate.ToString("dd/MM/yyyy") + " " + distinfo.Distribution_WaittingDate.ToLongTimeString();                        
                    }
                    else
                    {
                        txtDatetime.Text = distinfo.Distribution_WaittingDate.ToString("MM/dd/yyyy") + " " + distinfo.Distribution_WaittingDate.ToLongTimeString();                        
                    }
                }
                
            }
            catch
            {
                if (NCS.Library.AppEnv.GetLanguage() == "vi-VN")
                {
                    txtDatetime.Text = DateTime.Now.ToString("dd/MM/yyyy") + " " + DateTime.Now.ToLongTimeString();
                }
                else
                {
                    txtDatetime.Text = DateTime.Now.ToString("MM/dd/yyyy") + " " + DateTime.Now.ToLongTimeString();
                }
            }

            try
            {
                rdoContentRanks.SelectedValue = distinfo.Distribution_Rank.ToString();
                chkHotNews.Checked = distinfo.HotNewsInHomePage;
                chkLevel2.Checked = distinfo.RightPositionInLevel2;
            }
            catch
            {
                rdoContentRanks.SelectedValue = 1.ToString();
            }

            txtHour.Text = 0.ToString();
            //txtAvatar2width.Text = contentInfo.Content_AvatarWidth.ToString();
            //txtAvatar2Height.Text = contentInfo.Content_AvaterHeight.ToString();
            txtAvatarDes.Text = contentInfo.Content_AvatarDescription;
            chkIsComment.Checked = contentInfo.Content_IsComment;

            string zoneDeployed = "|";

            // zoneDeployed--> chuoi cac vi tri da xuat ban cua bai viet
            DataTable dtZoneDeployed = ZoneController.GetZonesDeployed(contentInfo.Content_ID);
            foreach (DataRow row in dtZoneDeployed.Rows)
            {
                zoneDeployed += row["Distribution_ZoneID"].ToString() + "|";
            }

            //foreach (ListItem item in lstZones.Items)
            //{
            //    if (zoneDeployed.IndexOf("|" + item.Value + "|") >= 0)
            //    {
            //        item.Selected = true;
            //    }
            //    else
            //    {
            //        item.Selected = false;
            //    }
            //}

            foreach (ListItem item in lstZones.Items) {
                if (item.Value == inzoneid.ToString())
                    item.Selected = true;
                else {
                    if (zoneDeployed.IndexOf("|" + item.Value + "|") >= 0)
                    { 
                        //cac vi tri xuat ban khac
                        item.Enabled = false;
                    }
                }
            }
            
        }
        private ContentInfo GetContent()
        {
            ContentInfo _contentInfo = new ContentInfo();

            _contentInfo.Content_Headline = ConvertUtility.ToString(txtHeadline.Text);
            //_contentInfo.Content_Teaser = MiscUtility.OptimiseContent(FCKeditor1.Value);
            _contentInfo.Content_Teaser = MiscUtility.OptimiseContent(this.txt_teaser.Text);
            _contentInfo.Content_Body = ConvertUtility.ToString(txtContent.Text);
            _contentInfo.Content_Avatar = txtAvatar.Text;
            _contentInfo.Content_AvatarDescription = txtAvatarDes.Text;
            _contentInfo.Content_AvatarWidth = Constants.ThumbWidth;
            _contentInfo.Content_AvaterHeight = Constants.ThumbHeight;
            _contentInfo.Content_ZoneID = ConvertUtility.ToInt32(dropZones.SelectedValue);
            _contentInfo.Content_UserID = CurrentUser.UserID;
            _contentInfo.Content_ModifiedUserID = CurrentUser.UserID;
            _contentInfo.Content_ApproveUser = CurrentUser.UserID;
            _contentInfo.Content_IsComment = chkIsComment.Checked;
            _contentInfo.SpecialAvatar = txtSpecialAvatar.Text;
            MultimediaUtility.SetAvatarThumbnail(Server.MapPath(_contentInfo.Content_Avatar), _contentInfo.Content_AvatarWidth, 0);
            MultimediaUtility.SetAvatarListThumbnail(Server.MapPath(_contentInfo.Content_Avatar), Constants.ThumbListWidth, 0);
            MultimediaUtility.SetAvatarSpecialThumbnail(Server.MapPath(_contentInfo.SpecialAvatar), Constants.ThumbSpecialWidth, Constants.ThumbSpecialHeight);
            _contentInfo.Content_Alias = lbAlias.Text;
            _contentInfo.Content_Source = ConvertUtility.ToString(txtSource.Text);
            _contentInfo.Content_Status = contentInfo.Content_Status;
            _contentInfo.Content_ID = contentInfo.Content_ID;
            _contentInfo.CheckInByUser = CurrentUser.UserID;
            _contentInfo.Event_ID = ConvertUtility.ToInt32(dropEvent.SelectedValue);
            _contentInfo.Content_SubTitle = txtSubTitle.Text;
            _contentInfo.Content_NoteBox = txtNoteBox.Text;
            _contentInfo.SetAlbum = chkAlbum.Checked;
            _contentInfo.Content_AvatarSource = ConvertUtility.ToInt32(dropPartner.SelectedValue);
            return _contentInfo;
        }

        private ContentVersionInfo GetContentVersion()
        {
            ContentVersionInfo _contentVersionInfo = new ContentVersionInfo();
                       
            _contentVersionInfo.Content_Version_ID = versionid;
            _contentVersionInfo.Content_ID = contentInfo.Content_ID;
            _contentVersionInfo.Content_Headline = ConvertUtility.ToString(txtHeadline.Text);
            //_contentVersionInfo.Content_Teaser = ConvertUtility.ToString(FCKeditor1.Value);
            _contentVersionInfo.Content_Teaser = ConvertUtility.ToString(this.txt_teaser.Text);
            _contentVersionInfo.Content_Body = ConvertUtility.ToString(txtContent.Text);
            _contentVersionInfo.Content_Avatar = txtAvatar.Text;
            _contentVersionInfo.Content_AvatarDescription = txtAvatarDes.Text;
            _contentVersionInfo.Content_AvatarWidth = Constants.ThumbWidth;
            _contentVersionInfo.Content_AvaterHeight = Constants.ThumbHeight;
            _contentVersionInfo.Content_Status = contentInfo.Content_Status;
            _contentVersionInfo.Content_ZoneID = ConvertUtility.ToInt32(dropZones.SelectedValue);
            _contentVersionInfo.Content_UserID = CurrentUser.UserID;
            _contentVersionInfo.Content_ModifiedUserID = CurrentUser.UserID;
            _contentVersionInfo.Content_IsComment = chkIsComment.Checked;
            _contentVersionInfo.SpecialAvatar = txtSpecialAvatar.Text;
            MultimediaUtility.SetAvatarThumbnail(Server.MapPath(contentInfo.Content_Avatar), contentInfo.Content_AvatarWidth, contentInfo.Content_AvaterHeight);
            MultimediaUtility.SetAvatarListThumbnail(Server.MapPath(contentInfo.Content_Avatar), Constants.ThumbListWidth, 0);
            MultimediaUtility.SetAvatarSpecialThumbnail(Server.MapPath(contentInfo.SpecialAvatar), Constants.ThumbSpecialWidth, 0);
            _contentVersionInfo.Content_Alias = lbAlias.Text;            
            _contentVersionInfo.Content_Source = ConvertUtility.ToString(txtSource.Text);
            _contentVersionInfo.CheckOutByUser = 0;            
            _contentVersionInfo.DeployedVersion = true;
            _contentVersionInfo.Content_SubTitle = txtSubTitle.Text;
            _contentVersionInfo.Content_NoteBox = txtNoteBox.Text;
            dropPartner.SelectedValue = contentInfo.Content_AvatarSource.ToString();
            return _contentVersionInfo;
        }

	    protected void btnCheckIn_Click(object sender, EventArgs e)
        {
            ContentInfo info = GetContent();

            if (contentInfo.Content_Status == (int)CMSWorkFlow.Waiting)
            {
                try
                {
                    ContentController.UpdateContent(info);
                    lblUpdateStatus.Text = MiscUtility.MSG_UPDATE_SUCCESS;
                }
                catch (Exception ex)
                {

                    lblStatusUpdate.Text = ex.ToString();
                }
            }
            else
            {

                try
                {
                    DistributionInfo distinfo = DistributionController.GetDistribution(DistributionController.GetDistID(contentInfo.Content_ID));
                    if (distinfo == null)
                    {
                        ContentController.UpdateContent(info);
                        lblUpdateStatus.Text = MiscUtility.MSG_UPDATE_SUCCESS;
                        return;
                    }
                    else
                    {
                        distinfo.Distribution_ID = distinfo.Distribution_ID;
                    }
                    if (distinfo.Distribution_ID > 0)
                    {
                        //int i1 = txtDatetime.Text.IndexOf("/");
                        //int l1 = txtDatetime.Text.Substring(0, i1).Length;
                        //string temp = txtDatetime.Text.Substring(i1 + 1);
                        //int i2 = temp.IndexOf("/");
                        //int l2 = temp.Substring(0, i2).Length;
                        //string time = txtDatetime.Text.Substring(l1 + 1, l2) + "/" + txtDatetime.Text.Substring(0, l1) + "/" + temp.Substring(l2 + 1);

                        //distinfo.Distribution_WaittingDate = ConvertUtility.ToDateTime(txtDatetime.Text);
                        string date = txtDatetime.Text;
                        string day = date.Substring(0, date.IndexOf("/"));
                        string month = date.Substring(date.IndexOf("/") + 1, 2);
                        string year = date.Substring(date.LastIndexOf("/") + 1, 4);
                        string hour = date.Substring(date.IndexOf(" ") + 1, date.IndexOf(":") - (date.IndexOf(" ") + 1));
                        string munite = date.Substring(date.IndexOf(":") + 1, 2);
                        string second = date.Substring(date.LastIndexOf(":") + 1, 2);

                        DateTime newdate = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day)).AddHours(Convert.ToInt32(hour)).AddMinutes(Convert.ToInt32(munite)).AddSeconds(Convert.ToInt32(second));

                        distinfo.Distribution_WaittingDate = newdate;

                        distinfo.Distribution_ID = distinfo.Distribution_ID;
                        distinfo.Distribution_WaittingHour = ConvertUtility.ToInt32(txtHour.Text);
                        distinfo.Distribution_Rank = ConvertUtility.ToInt32(rdoContentRanks.SelectedValue);
                        distinfo.HotNewsInHomePage = chkHotNews.Checked;
                        distinfo.RightPositionInLevel2 = chkLevel2.Checked;

                        DistributionController.UpdatePostDate(distinfo);
                        DistributionController.SetDistributionRank(distinfo.Distribution_ID, distinfo.Distribution_Rank);

                        if (contentInfo.Event_ID != 0 ) 
                        {
                            EventController.Event_RemoveDistribution(contentInfo.Event_ID, distinfo.Distribution_ID);
                           
                            //EventController.Event_AddDistribution(ConvertUtility.ToInt32(dropEvent.SelectedValue), distinfo.Distribution_ID);                          
                            EventController.Event_AddDistribution(ConvertUtility.ToInt32(dropEvent.SelectedValue), distinfo.Distribution_ContentID);
                        }                        
                        else if(contentInfo.Event_ID == 0 && ConvertUtility.ToInt32(dropEvent.SelectedValue) > 0)  // bai viet chua thuoc su kien nao
                        {
                           // EventController.Event_AddDistribution(ConvertUtility.ToInt32(dropEvent.SelectedValue), distinfo.Distribution_ID);
                            EventController.Event_AddDistribution(ConvertUtility.ToInt32(dropEvent.SelectedValue), distinfo.Distribution_ContentID);
                        }

                        ContentController.UpdateContent(info);

                        lblUpdateStatus.Text =  Constants.MSG_Deploy + "<br> ";
                      //  lstZones.Items.FindByValue(dropZones.SelectedValue).Selected = true;
                        
                        string strItemSelect = string.Empty;
                        foreach (ListItem item in lstZones.Items)
                        {
                            
                            if (item.Selected)
                            {
                                int zoneID = ConvertUtility.ToInt32(item.Value);
                                strItemSelect += "|" + zoneID;

                                //kt : if (zone duoc selected <> inzoneid)
                                if (zoneID != inzoneid)
                                {
                                    //them vi tri moi
                                    DistributionInfo newDist = new DistributionInfo();
                                    newDist.Distribution_ContentID = contentInfo.Content_ID;
                                    newDist.Distribution_ZoneID = zoneID;
                                    newDist.Distribution_Rank = ConvertUtility.ToInt32(rdoContentRanks.SelectedValue);
                                    newDist.Distribution_ExpireDate = new DateTime(Convert.ToInt32(dropExpireYear.SelectedValue), Convert.ToInt32(dropExpireMonth.SelectedValue), Convert.ToInt32(dropExpireDay.SelectedValue));
                                    newDist.Distribution_WaittingDate = newdate;
                                    newDist.Distribution_WaittingHour = ConvertUtility.ToInt32(txtHour.Text);
                                    newDist.Distribution_View = distinfo.Distribution_View;
                                    newDist.Portal_ID = ConvertUtility.ToInt32(AppEnv.PortalId());
                                    newDist.HotNewsInHomePage = false;
                                    newDist.RightPositionInLevel2 = false;
                                    DistributionController.AddDistribution(newDist);
                                    
                                    
                                }
                                lblUpdateStatus.Text += item.Text + ",<br>";
                               
                            }
                            //else
                            //{
                            //    DistributionController.RemoverInZoneID(contentInfo.Content_ID,
                            //                                           Convert.ToInt32(item.Value));
                            //}
                        }
                        if (!string.IsNullOrEmpty(strItemSelect))
                        {
                            strItemSelect += "|";
                            string publish_currentzone = "|" + inzoneid + "|";
                            if (!strItemSelect.Contains(publish_currentzone))
                            {
                                //remover bai viet tai vi tri publish_currentzone
                                DistributionController.RemoverInZoneID(contentInfo.Content_ID, Convert.ToInt32(inzoneid));
                            }
                        }
                        else {
                            //khong co vi tri nao duoc chon --> remove bai tai vi tri publish_currentzone
                            DistributionController.RemoverInZoneID(contentInfo.Content_ID, Convert.ToInt32(inzoneid));
                        }

                       // lblUpdateStatus.Text = lblUpdateStatus.Text.Substring(0, lblUpdateStatus.Text.Length - 5) ;
                    }
                    else
                    {
                        lblStatusUpdate.Text = MiscUtility.MSG_UPDATE_ERROR;
                    }

                    #region xoa bo dem
                    
                    DataTable dt = PortalCacheController.GetPortalCacheByPortalIdAndZoneID(ConvertUtility.ToInt32(AppEnv.PortalId()), ConvertUtility.ToInt32(dropZones.SelectedValue));

                    HttpContext context = HttpContext.Current;
                    IEnumerator dcEnum = context.Cache.GetEnumerator();
                    DataCaching dc = new DataCaching();
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            dc.RemoveCache(ConvertUtility.ToString(dt.Rows[i]["CacheKey"]));
                        }
                    }
                    else
                        dc.RemoveAll();

                    #endregion end xoa bo dem
                   
                }
                catch (Exception ex)
                {
                    lblStatusUpdate.Text = ex.ToString();
                }
            }
            ContentController.UnLockContent(contentId);
            if (chkAlbum.Checked)
            {
                //Response.Write("<script>alert('" + lblUpdateStatus.Text + "\n\r Bài viết đã được chọn có album, Chương trình sẽ tự chuyển đến trang quản lý Album cho bài viết này.'</script>");
                lblUpdateStatus.Text += "<br/> Bài viết đã được chọn có album, <a href=\"" + AppEnv.AdminUrlParams("picturelistforcontent") + "&contentid=" + contentId + " \">bấm vào đây chuyển đến trang tạo Album cho bài viết này.</a>";
                //Response.Redirect(AppEnv.AdminUrlParams("picturelist") + "&contentid=" + contentInfo.Content_ID);
            }

            this.AddLog("CMS", " try checkin contetn \"" + info.Content_Headline + "\" success");
            this.contentInfo = info;
        }

        protected void btnUndoCheckOut_Click(object sender, EventArgs e)
        {
            //update gia tri UserID cua truong checkoutby = 0
            //ContentVersionController.DeleteContentVersion(versionid);
            ContentController.UnLockContent(contentId);
            string redirecturl = Request.QueryString["reurl"];
            if (string.IsNullOrEmpty(redirecturl))
                Response.Redirect(AppEnv.AdminUrlParams("cms_distributedlist"));
            else
                Response.Redirect(AppEnv.AdminUrlParams(redirecturl));
        }

        protected void cmdHuy_Click(object sender, EventArgs e)
        {
            txtHeadline.Text = string.Empty;
            txtAvatar.Text = string.Empty;
            txtSpecialAvatar.Text = string.Empty;
            //FCKeditor1.Value = string.Empty;
            this.txt_teaser.Text = string.Empty;
            txtContent.Text = string.Empty;
            foreach (ListItem item in lstZones.Items)
            {
                item.Selected = false;
            }
        }

        protected void dropPortal_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadZones();
        }
      
        protected void btnCreateNewVersion_Click(object sender, EventArgs e)
        {
            btnCheckIn_Click(null, null);
            ContentVersionInfo versionInfo = GetContentVersion();
            versionid = ContentVersionController.AddContentVersion(versionInfo);
            this.AddLog("CMS", " try create new version contetn \"" + versionInfo.Content_Headline + "\" success");
        }
	}
}